using System;
using System.Collections.Generic;
using System.Text;

using System.Net;
using System.Net.Sockets;

namespace Parsifal
{
    public class ManageSendDataClient
    {
        private eWordCodeForProtocol iWordCodeForProtocol;

        //LOG
        private Utility iUtility;

        public ManageSendDataClient(Utility aUtility)
        {
            iWordCodeForProtocol = new eWordCodeForProtocol();
        }

        public void SendNickSend(Socket remote, string nick,string addr)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendNickSend : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mNickSend + eWordCodeForProtocol.mMainSeparator;
                data += nick + "/" + addr +  "##";

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendNickSend : dati " + data, NLog.LogLevel.Info);


            }
            catch(Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendNick");
            }
        }

        public void SendConnectToRec(Socket remote)
        {
            try
            {

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendConnectoRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mConnectToRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendConnecttoResc : dati  " + data, NLog.LogLevel.Info);

            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendConnectToRec");
            }

        }

        public void SendCreateServerRec(Socket remote)
        {
            try
            {

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendCreateServerRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mCreateServerRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendCreateServer : dati  " + data, NLog.LogLevel.Info);

            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendCreateServer");
            }
        }

        public void SendMessage(Socket remote, string nick, string msg)
        {
            try
            {
                string data = eWordCodeForProtocol.mMsgSend + eWordCodeForProtocol.mMainSeparator;
                data += nick + "/" + msg + "##";

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendMessage : dati  " + data, NLog.LogLevel.Info);


            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendMessage");
            }
        }

        public void SendMessageReceived(Socket remote)
        {
            try
            {

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendMessageReceived : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mMsgSendRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendMessageReceived : dati  " + data, NLog.LogLevel.Info);

            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendMessageReceived");
            }
        }

        public void SendPlaylistItemRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPlaylistItemRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPlaylistITemRec");
            }
        }

        public void SendPlaylistItemAdd(Socket remote, PlaylistItem aItem)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistItemAdd : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPlaylistItemAdd + eWordCodeForProtocol.mMainSeparator;
                data += aItem.Artist + "/" + aItem.Song + "/" + aItem.Duration + "/" + aItem.NickServer + "##";

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistItemAdd : dati  " + data);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPlaylistItemAdd");
            }
        }

        public void SendPLaylistItemRem(Socket remote, PlaylistItem aItem)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPLaylistItemRem : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPlaylistItemRem + eWordCodeForProtocol.mMainSeparator;
                data += aItem.Artist + "/" + aItem.Song + "/" + aItem.Duration + "/" + aItem.NickServer + "##";

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPLaylistItemRem : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPLaylistItemRem");
            }
        }


        public void SendPlaylistItemAddRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemAddRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPLaylistItemAddRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemAddRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPlaylistITemAddRec");
            }
        }

        public void SendPlaylistItemRemoveRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemRemRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPlaylistItemRemRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemRemRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPlaylistITemRemRec");
            }
        }

        public void SendPlaylistItemLastRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemLastRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mPlaylistItemLastRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendPlaylistITemLastRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendPlaylistITemLastRec");
            }
        }

        public void SendSongActiveRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSongActive : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mSongActiveRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSongActive : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendSongActive");
            }
        }

        public void SendSpeackerOffRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSpeackerOffRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mSpeackerOffRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSpeackerOffRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendSpeackerOffRec");
            }
        }

        public void SendSpeackerOnRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSpeackerOnRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mSpeackerOnRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendSpeackerOnRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendSpeackerOnRec");
            }
        }

        public void SendStopServerRec(Socket remote)
        {
            try
            {
                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendStopServerRec : enter", NLog.LogLevel.Info);

                string data = eWordCodeForProtocol.mStopServerRec + eWordCodeForProtocol.mMainSeparator;

                byte[] bOut = iUtility.ConvertStringToBye(data);

                remote.Send(bOut);

                iUtility.LogEvent("MANAGE SEND DATA CLIENT : fx SendStopServerRec : dati  " + data, NLog.LogLevel.Info);
            }
            catch (Exception err)
            {
                throw new Exception("Impossibile inviare il pacchetto SendStopServerRec");
            }
        }
    }
}
